<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>更新成绩信息</title>
    <link rel="stylesheet" href="../../css/ok/oksub.css">
    <script type="text/javascript" src="../../libs/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form" lay-filter="achievementval">
        <div class="layui-form-item">
            <label class="layui-form-label">学期</label>
            <div class="layui-input-block">
                <input type="hidden" name="achieveid" required lay-verify="required"
                       autocomplete="off" class="layui-input">
                <select name="semester" lay-verify="required">
                    <option value="选择学期" disabled>选择学期</option>
                    <option value="大一上学期">大一上学期</option>
                    <option value="大一下学期">大一下学期</option>
                    <option value="大二上学期">大二上学期</option>
                    <option value="大二下学期">大二下学期</option>
                    <option value="大三上学期">大三上学期</option>
                    <option value="大三下学期">大三下学期</option>
                    <option value="大四上学期">大四上学期</option>
                    <option value="大四下学期">大四下学期</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">科目</label>
            <div class="layui-input-block">
                <input type="text" name="subject" required lay-verify="required"
                       placeholder="请输入专业科目"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">科目评分</label>
            <div class="layui-input-block">
                <select name="score" lay-verify="required">
                    <option value="科目评级" disabled>科目评级</option>
                    <option value="A">A</option>
                    <option value="B">B</option>
                    <option value="C">C</option>
                    <option value="D">D</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formAchievement">修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>

<!--js逻辑-->
<script src="../../libs/layui/layui.js"></script>
<script src="../../js/model.js"></script>
<script>
    let initData;

    function initForm(data) {
        console.log(data)
        let jsonString = JSON.stringify(data);
        console.log(jsonString);
        initData = JSON.parse(jsonString);
    }

    layui.use(["element", "form", "okLayer", "okUtils"], function () {
        let form = layui.form;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        form.val("achievementval", initData);
        okLoading.close();
        //获取student
        var student = JSON.parse(window.sessionStorage.getItem("student"));

        form.on("submit(formAchievement)", function (data) {
            console.log(data.field)
            var achievement = new Achievemen(data.field.achieveid, data.field.subject, data.field.score, data.field.semester, student);
            okUtils.ajax("/ygssecs/upAchievement", "post", {achievejson: JSON.stringify(achievement)}, true).done(function (response) {
                if (response.code == 200) {
                    okLayer.greenTickMsg(response.msg, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    });
                } else {
                    okLayer.yellowSighMsg(response.msg);
                }
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    })
</script>
</body>
</html>